﻿Public Class BlockFourHomeworkSectionTwo
    Dim QuestionNumber As Integer
    Dim dtmTest, dtmTest2 As Date
    Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Declare the Array as 10 rows and 3 columns
    Dim ArrayMax As Integer = 28 'One number past the end of actual info in array
    Dim HWQuestions(ArrayMax, 7) As String
    Dim intResponse As Integer
    Dim intQuestionCount As Integer = 0
    Dim intAnswerCount As Integer = 0
    Dim intReferenceCount As Integer = 0
    Dim intFirstRun As Integer = 1
    Dim strUser As String = "Enter Last Name"
    Dim strAnswer, strAnswer2, strAnswer3, strAnswer4, strAnswer5, _
     strAnswer6, strAnswer7, strAnswer8, strAnswer9, strAnswer10, strAnswer11 As String
    Dim intChoiceACount As Integer = 2
    Dim intChoiceBCount As Integer = 3
    Dim intChoiceCCount As Integer = 4
    Dim intChoiceDCount As Integer = 5

    Shared Property MidiParent As MainForm

    Private Sub CloseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub BlockTwoHomeworkSectionOne_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtObj.Text = "Objectives:" + vbCrLf + "- Given proper student instructional materials, identify the operating principles of the power supply circuits and power supply signal flow path in the power distribution block diagram."
        If (System.IO.File.Exists(filename & "\Homework\Block 4\Block 4 Section 2.txt")) Then
            intResponse = MsgBox("This assignment has already been completed.  Are you sure you want to delete the current assignment and reaccomplish it?", 4, "Confirm Assignment Deletion")
            If intResponse = MsgBoxResult.Yes Then
                System.IO.File.Delete(filename & "\Homework\Block 4\Block 4 Section 2.txt")
                System.IO.File.Create(filename & "\Homework\Block 4\Block 4 Section 2.txt").Dispose()
            ElseIf intResponse = MsgBoxResult.No Then
                Me.Close()
            End If
        End If
        If (Not System.IO.File.Exists(filename & "\Homework\Block 4\Block 4 Section 2.txt")) Then
            System.IO.File.Create(filename & "\Homework\Block 4\Block 4 Section 2.txt").Dispose()
        End If
        If (Not System.IO.File.Exists(filename & "\Instructor\Block 4\Block 4 Section 2.txt")) Then
            System.IO.File.Create(filename & "\Instructor\Block 4\Block 4 Section 2.txt").Dispose()
        End If
        strUser = InputBox("Please enter last name", strUser)
        If strUser Is "" Then
            Me.Close()
        End If
        '************************************************
        '****** Questions Are Loaded Here****************
        '******* Column 1 is Questions (Preloaded)*******
        '******* Column 2 is Accepts Students Answer*****
        '******* Column 3 is Reference ******************
        HWQuestions(1, 1) = ""
        HWQuestions(1, 2) = ""
        HWQuestions(1, 4) = ""
        HWQuestions(1, 5) = ""
        HWQuestions(1, 6) = ""
        HWQuestions(1, 3) = ""

        HWQuestions(2, 1) = ""
        HWQuestions(2, 2) = ""
        HWQuestions(2, 4) = ""
        HWQuestions(2, 5) = ""
        HWQuestions(2, 6) = ""
        HWQuestions(2, 3) = ""

        HWQuestions(3, 1) = ""
        HWQuestions(3, 2) = ""
        HWQuestions(3, 4) = ""
        HWQuestions(3, 5) = ""
        HWQuestions(3, 6) = ""
        HWQuestions(3, 3) = ""

        HWQuestions(4, 1) = ""
        HWQuestions(4, 2) = ""
        HWQuestions(4, 4) = ""
        HWQuestions(4, 5) = ""
        HWQuestions(4, 6) = ""
        HWQuestions(4, 3) = ""

        HWQuestions(5, 1) = ""
        HWQuestions(5, 2) = ""
        HWQuestions(5, 4) = ""
        HWQuestions(5, 5) = ""
        HWQuestions(5, 6) = ""
        HWQuestions(5, 3) = ""

        HWQuestions(6, 1) = ""
        HWQuestions(6, 2) = ""
        HWQuestions(6, 4) = ""
        HWQuestions(6, 5) = ""
        HWQuestions(6, 6) = ""
        HWQuestions(6, 3) = ""

        HWQuestions(7, 1) = ""
        HWQuestions(7, 2) = ""
        HWQuestions(7, 4) = ""
        HWQuestions(7, 5) = ""
        HWQuestions(7, 6) = ""
        HWQuestions(7, 3) = ""

        HWQuestions(8, 1) = ""
        HWQuestions(8, 2) = ""
        HWQuestions(8, 4) = ""
        HWQuestions(8, 5) = ""
        HWQuestions(8, 6) = ""
        HWQuestions(8, 3) = ""

        HWQuestions(9, 1) = ""
        HWQuestions(9, 2) = ""
        HWQuestions(9, 4) = ""
        HWQuestions(9, 5) = ""
        HWQuestions(9, 6) = ""
        HWQuestions(9, 3) = ""

        HWQuestions(10, 1) = ""
        HWQuestions(10, 2) = ""
        HWQuestions(10, 4) = ""
        HWQuestions(10, 5) = ""
        HWQuestions(10, 6) = ""
        HWQuestions(10, 3) = ""

        HWQuestions(11, 1) = ""
        HWQuestions(11, 2) = ""
        HWQuestions(11, 4) = ""
        HWQuestions(11, 5) = ""
        HWQuestions(11, 6) = ""
        HWQuestions(11, 3) = ""

        HWQuestions(12, 1) = ""
        HWQuestions(12, 2) = ""
        HWQuestions(12, 4) = ""
        HWQuestions(12, 5) = ""
        HWQuestions(12, 6) = ""
        HWQuestions(12, 3) = ""

        HWQuestions(13, 1) = ""
        HWQuestions(13, 2) = ""
        HWQuestions(13, 4) = ""
        HWQuestions(13, 5) = ""
        HWQuestions(13, 6) = ""
        HWQuestions(13, 3) = ""

        HWQuestions(14, 1) = ""
        HWQuestions(14, 2) = ""
        HWQuestions(14, 4) = ""
        HWQuestions(14, 5) = ""
        HWQuestions(14, 6) = ""
        HWQuestions(14, 3) = ""

        HWQuestions(15, 1) = ""
        HWQuestions(15, 2) = ""
        HWQuestions(15, 4) = ""
        HWQuestions(15, 5) = ""
        HWQuestions(15, 6) = ""
        HWQuestions(15, 3) = ""

        HWQuestions(16, 1) = "Close"

        Next_Question(HWQuestions)
    End Sub

    Private Sub btnNextQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnNextQuestion.Click
        Next_Question(HWQuestions)
    End Sub
    Private Sub Clear_Display()
        txtQuestion.Clear()

    End Sub

    Public Function Next_Question(HWQuestions As String(,))
        If intQuestionCount > 0 Then
            WriteToFile()
        End If
        If btnNextQuestion.Text = "Done" Then
            Me.Close()
            OpenResults()
        End If
        intQuestionCount = intQuestionCount + 1
        If intQuestionCount = 15 Then
            btnNextQuestion.Text = "Done"
        End If
        txtQuestion.Text = HWQuestions(intQuestionCount, 1)
        txtChoiceA.Text = HWQuestions(intQuestionCount, 2)
        txtChoiceB.Text = HWQuestions(intQuestionCount, 4)
        txtChoiceC.Text = HWQuestions(intQuestionCount, 5)
        txtChoiceD.Text = HWQuestions(intQuestionCount, 6)
        intReferenceCount = intReferenceCount + 1
        txtReference.Text = HWQuestions(intReferenceCount, 3)

        Return intQuestionCount
    End Function
    Private Sub WriteToFile()
        Dim Integrity As String = (filename & "\Instructor\Block 4\Block 4 Section 2.txt")
        Dim Results As String = (filename & "\Homework\Block 4\Block 4 Section 2.txt")

        '***********Output to hidden file for Instructor Check***********
        If System.IO.File.Exists(Integrity) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Integrity, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
            If chkboxChoiceA.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  A: " & txtChoiceA.Text)
            ElseIf chkboxChoiceB.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  B: " & txtChoiceB.Text)
            ElseIf chkboxChoiceC.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  C: " & txtChoiceC.Text)
            ElseIf chkboxChoiceD.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  D: " & txtChoiceD.Text)
            End If
            If chkboxChoiceA.CheckState = CheckState.Unchecked Then
                If chkboxChoiceB.CheckState = CheckState.Unchecked Then
                    If chkboxChoiceC.CheckState = CheckState.Unchecked Then
                        If chkboxChoiceD.CheckState = CheckState.Unchecked Then
                            hiddenWriter.WriteLine("No Answer Chosen")
                        End If
                    End If
                End If
            End If
            hiddenWriter.WriteLine("Reference: " & txtReference.Text)
            hiddenWriter.WriteLine()
            If intQuestionCount = 15 Then
                hiddenWriter.WriteLine("Block 4 Section 2 Homework Complete")
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Integrity")
        End If

        '******Output to file for Student to review***********
        If System.IO.File.Exists(Results) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Results, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
            If chkboxChoiceA.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  A: " & txtChoiceA.Text)
            ElseIf chkboxChoiceB.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  B: " & txtChoiceB.Text)
            ElseIf chkboxChoiceC.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  C: " & txtChoiceC.Text)
            ElseIf chkboxChoiceD.CheckState = 1 Then
                hiddenWriter.WriteLine("Answer:  D: " & txtChoiceD.Text)
            End If
            If chkboxChoiceA.CheckState = CheckState.Unchecked Then
                If chkboxChoiceB.CheckState = CheckState.Unchecked Then
                    If chkboxChoiceC.CheckState = CheckState.Unchecked Then
                        If chkboxChoiceD.CheckState = CheckState.Unchecked Then
                            hiddenWriter.WriteLine("No Answer Chosen")
                        End If
                    End If
                End If
            End If
            'hiddenWriter.WriteLine("Reference: " & txtReference.Text)
            hiddenWriter.WriteLine()
            If intQuestionCount = 15 Then
                hiddenWriter.WriteLine("Block 4 Section 2 Homework Complete")
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Results")
        End If
        If intQuestionCount > 0 Then
            chkboxChoiceA.CheckState = CheckState.Unchecked
            chkboxChoiceB.CheckState = CheckState.Unchecked
            chkboxChoiceC.CheckState = CheckState.Unchecked
            chkboxChoiceD.CheckState = CheckState.Unchecked
        End If
    End Sub

    Private Sub OpenResults()
        Dim p As Process = Process.Start(filename & "\Homework\Block 4\Block 4 Section 2.txt")
    End Sub
End Class
